package com.lcx.movie.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lcx.movie.common.Rep;
import com.lcx.movie.entity.Hall;
import com.lcx.movie.service.HallService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 李丽君
 * @version 1.0
 * @Description 放映厅控制层对象
 * @date 2025/2/10 10:02
 */
@CrossOrigin(origins = "*")
@RestController
public class HallController {
    @Autowired
    private HallService hallService;
    /**
     * 根据影院id查询所有影厅[分页查询]
     * @param cinemaId 影院id
     * @return 影厅集合
     */
    @GetMapping("selectHallByCinemaId")
    public Rep selectHallByCinemaId(int cinemaId) {
        List<Hall> hallList = hallService.selectHallByCinemaId(cinemaId);
        return new Rep().addData("hallList", hallList);
    }

    /**
     * 新增放映厅
     * @param hall 放映厅对象
     * @return 受影响的行数
     */
    @PostMapping("/addHall")
    public String addHall(@RequestBody Hall hall){
        int addHall = hallService.addHall(hall);
        return addHall>0?"新增放映厅成功":"新增放映厅失败";
    }
    /**
     * 检查在数据库里是否有重复的放映厅名字
     * @param hallName 放映厅名称
     * @param cinemaId 影院id
     * @return 受影响的行数
     */
    @GetMapping("/checkHallNameInDatabase")
    public String checkHallNameInDatabase(@Param("hallName") String hallName, @Param("cinemaId") int cinemaId){
        int hallNameInDatabase = hallService.checkHallNameInDatabase(hallName, cinemaId);
        if (hallNameInDatabase == 0){
            return "not exists";
        }else {
            return "exists";
        }
    }
    /**
     * 根据放映厅id删除放映厅
     * @param hallId 放映厅id
     * @return 受影响的行数
     */
    @GetMapping("/deleteHall")
    public String deleteHall(@Param("hallId") int hallId){
        int deleteHall = hallService.deleteHall(hallId);
        return deleteHall>0?"删除放映厅成功":"删除放映厅失败";
    }
    /**
     * 修改放映厅信息
     * @param hall 放映厅实体
     * @return 受影响的行数
     */
    @PostMapping("/updateHall")
    public String updateHall(@RequestBody Hall hall){
        int updateHall = hallService.updateHall(hall);
        return updateHall>0?"修改放映厅信息成功":"修改放映厅信息失败";
    }

}
